﻿using System;
using Furesoft.Papi.AST;

namespace Furesoft.Papi
{
    public class NodeReporter : IObserver<INode>
    {
        private IDisposable unsubscriber;

        public virtual void Subscribe(IObservable<INode> provider)
        {
            if (provider != null)
                unsubscriber = provider.Subscribe(this);
        }

        public virtual void OnCompleted()
        {
            Console.WriteLine("Successfull");
            this.Unsubscribe();
        }

        public virtual void OnError(Exception e)
        {
            Console.WriteLine(e.Message);
        }

        public virtual void OnNext(INode value)
        {
            Console.WriteLine(value);
        }

        public virtual void Unsubscribe()
        {
            unsubscriber.Dispose();
        }
    }
}